// 获取tbody
var myTbody = document.getElementById("myTbody");
var add = document.getElementsByClassName("add")[0];
var modify = document.getElementsByClassName("modify")[0];
var inps = document.getElementsByClassName("inp")[0];
var seek = document.getElementsByClassName("seek")[0];
seek.onclick = function () {
    myTbody.innerHTML = "";
    fileManagerList();
    console.log(111);
}
// 点击添加，出现motaikuang
add.onclick = function () {
    // 调用myModel
    myModel({
        mask: true,//显示蒙版
        //标题
        content_item1: `
        <div class="title">添加预招生</div>
                    <div class="userupdate">
                        
                        <div class="left">
                            <div class="name">姓名：<input type="text" id="username"></div>
                        <div class="sex">性别：<select name="" id="usersex">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                            </div>
                        <div class="phone">电话：<input type="text" id="userphone"></div>
                        </div>
                        <div class="right">
                            <div class="class1">预报班级：<select name="" id="Class">
                                <option value="0">UI设计</option>
                                <option value="1">前端开发</option>
                                <option value="2">后端开发</option>
                            </select></div>
                        <div class="date">预报到日期：<input type="date" id="Date"></div>
                    </div>
                `,
        fun: function () {
            // 执行添加的函数
            alert("添加成功");
            addUser();
        }
    })
}

// 封装用户列表渲染
function fileManagerList() {
    var pageIndex = 1;
    var pageSize = 6;
    // var pageCount = 0;
    // 调接口
    var data = {
        pageSize: pageSize,
        pageIndex: pageIndex,
        fileManagerType: "预招生",
        fileManagerName: inps.value
    }
    ajax.post("http://192.168.199.101:8080/BaorSystem/fileManager/fileManagerList", data, function (res) {
        if (res.code == 200) {
            var fileManagerList = res.dataset;
            // 当用户列表重新渲染时，用户列表需清空
            myTbody.innerHTML = " ";
            // 获取总页数
            pageCount = fileManagerList.pageCount;
            // 获取用户列表进行页面渲染
            for (var i = 0; i < fileManagerList.fileManagerList.length; i++) {
                var newTr = document.createElement("tr");
                newTr.innerHTML = `
                      <td>${res.dataset.fileManagerList[i].fileManagerName}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerSex}</td>
                         <td>${res.dataset.fileManagerList[i].clazzName}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerDate}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerPhone}</td>
                        <td>
                            <button class="modify" onclick="modifyUser(${fileManagerList.fileManagerList[i].fileManagerId})">修改</button>
                            <button class="del" onclick="delUser(${fileManagerList.fileManagerList[i].fileManagerId})">删除</button>
                        </td>
                    `
                myTbody.appendChild(newTr)
            }
            console.log(fileManagerList, pageCount);
        }
    })
}
fileManagerList()
// 封装删除
function delUser(id) {
    // 调接口
    ajax.post(`http://192.168.199.101:8080/BaorSystem/fileManager/deleteFileManager`, { fileManagerId: id }, function (res) {
        if (res.code == 200) {
            alert("该用户删除成功");
            // 重新渲染用户列表
            fileManagerList();
        }
    })
}
// 封装添加
function addUser() {
    //  调添加用户接口
    var data = {
        fileManagerType: "预招生",
        fileManagerName: document.getElementById("username").value,
        fileManagerSex: document.getElementById("usersex").value,
        fileManagerPhone: document.getElementById("userphone").value,
        clazzId: Number(document.getElementById("Class").value),
        fileManagerDate: document.getElementById("Date").value
    }
    ajax.post('http://192.168.199.101:8080/BaorSystem/fileManager/addFileManager', data, function (res) {
        console.log(res);
        fileManagerList();
    })

}
// 封装修改
function modifyUser(id) {
    // 模态框显示
    myModel({
        mask: true,//显示蒙版
        content_item1: `
                    <div class="title">修改预招生</div>
                    <div class="userupdate">

                        <div class="left">
                            <div class="name">姓名：<input type="text" id="username"></div>
                        <div class="sex">性别：<select name="" id="usersex">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                            </div>
                        <div class="phone">电话：<input type="text" id="userphone"></div>
                        </div>
                        <div class="right">
                            <div class="class1">预报班级：<select name="" id="Class">
                                <option value="0">UI设计</option>
                                <option value="1">前端开发</option>
                                <option value="2">后端开发</option>
                            </select></div>
                        <div class="date">预报到日期：<input type="date" id="Date"></div>
                    </div>
                `,
        fun: function () {

            ajax.post("http://192.168.199.101:8080/BaorSystem/fileManager/updateFileManager", { fileManagerId: id }, function (res) {
                if (res.code == 200) {
                    alert('当前用户修改成功');
                    fileManagerList();
                }
            })
        }
    })
}
var journal = document.getElementsByClassName("journal")[0];
journal.onclick = function () {
    location.href = "./diary.html";
}
//审核系统
var vet = document.getElementsByClassName("vet")[0];
vet.onclick = function () {
    location.href = "./audit.html";
}
//用户管理
var user = document.getElementsByClassName("user")[0];
user.addEventListener('click', function () {
    location.href = "./UserMage.html";
});
//班级管理
var classs = document.getElementsByClassName("classs");
classs[0].onclick = function () {
    location.href = "./ClassManagement.html";
}
//日常
var routine = document.getElementsByClassName("routine")[0];
routine.onclick = function () {
    location.href = "./daily.html";
}
//学生档案
var archives = document.getElementsByClassName("archives")[0];
archives.onclick = function () {
    location.href = "./student file.html";
}
//项目管理
var project = document.getElementsByClassName("project")[0];
project.onclick = function () {
    location.href = "./projectmanagement.html";
}
//出差记录
var travel = document.querySelector(".travel");
travel.addEventListener('click', function () {
    location.href = "./business.html";
});
//请假记录
var excused = document.querySelector(".excused");
excused.addEventListener('click', function () {
    location.href = "./vacate.html";
});
//考勤记录
var presence = document.querySelector(".presence");
presence.addEventListener('click', function () {
    location.href = "./clock.html";
});